<template>
  <div class="base-container" id="main">
    <t-loading text="加载中..." :fullscreen="false" attach="#main" :loading="applyLoading" size="medium">
    </t-loading>
    <t-steps :current="activeForm" status="process" :onChange="onCurChanged">
      <t-step-item title="基本信息" :content="isSubmit('projectId')">
      </t-step-item>
      <t-step-item title="立项背景和依据" :content="isSubmit('backgroundId')"></t-step-item>
      <t-step-item title="研究方案" :content="isSubmit('approachId')"></t-step-item>
      <t-step-item title="研究基础" :content="isSubmit('basicstudyId')"></t-step-item>
      <t-step-item title="单位信息" :content="isSubmit('companyId')"></t-step-item>
      <t-step-item title="研究人员" :content="isSubmit('memberId')"></t-step-item>
      <t-step-item title="经费预算" :content="isSubmit('budgetId')"></t-step-item>
      <t-step-item title="附件信息" :content="isSubmit('fileId')"></t-step-item>
    </t-steps>

    <!-- 基本信息 -->
    <t-form ref="form" :key="activeForm" v-if="activeForm === 0" class="step-form" :data="formData" @submit="onSubmit"
      :rules="rules" labelWidth="180px">
      <t-alert v-if="site_tag === 'jtt'" style="margin-bottom: 14px" theme="info" title="填写说明：">
        <div slot="message">
          <p class="span-txt">
            一、填写申报书以前，请先查阅《江西省交通运输厅科技项目管理办法》有关规定和本年度科技项目申报指南。申报书内各项内容，应实事求是，认真填写，表述明确。外来语要同时用原文和中文表达，第一次出现的缩略词，须注明全称。
          </p>
          <!--            <p class="span-txt">二、封面中的计划类别为：软科学研究、应用技术研究、交通信息化、高新技术研发、成果转化与推广、标准规范和重点工程科技项目。</p>-->
          <p>二、封面中的计划类别为：一般科技项目（基础设施、运输服务、数字交通、交通安全、绿色交通、标准化、决策支持）、重大研发科技项目和重点工程科技项目。</p>
          <p class="span-txt">三、项目归口管理单位主要指各设区市交通运输局、公路事业发展中心，省直管试点县（市）交通运输局，厅直属各单位、省交投集团、省港口集团等有关单位。</p>
          <!--            <p class="span-txt">-->
          <!--              四、申报者须登录江西交通信息网（www.jxjt.gov.cn），由“江西交通科技信息管理系统”注册进入，进行网上填报申报书；完成后，必须发送电子文档，并采用标准A4纸打印纸质申报材料（一式2份），报送厅科技教育处。</p>-->
          <p>四、申报者须登录http://111.75.227.156:20100，进行网上填报申报书。</p>
          <p class="span-txt">五、项目负责人主持在研厅科技项目不得超过2项（含此次申报数），在研项目合同到期(含申请延期到期)未申请验收的不得申报。</p>
          <p class="span-txt">六、申报书各填写内容，要求达到可行性论证和技术方案深度，可附必要文件资料。</p>
          <p class="span-txt">七、申报单位须在本年度申报规定的日期内完成，逾期申报的项目纳入下年度科技项目管理。</p>
          <p class="span-txt">八、表格里的文字要求按默认的格式填写，若加小标题，请在默认格式上加粗。</p>
          <!--            <p class="span-txt">九、本申报书样式可在江西交通信息网（www.jxjt.gov.cn）下载。</p>-->
          <p class="span-txt">九、通讯地址：江西省南昌市红谷滩卧龙路1999号，江西省交通运输厅科技教育处，邮政编码：330036。</p>
        </div>
      </t-alert>
      <t-alert v-else style="margin-bottom: 14px" theme="info" title="填写说明：">
        <div slot="message">
          <p class="span-txt">
            一、填写建议书以前，请先查阅《江西省交通投资集团有限责任公司科技创新管理办法》和本年度科技项目申报通知有关规定。建议书内各项内容，应实事求是，认真填写，表述明确。外来语要同时用原文和中文表达，第一次出现的缩略词，须注明全称。
          </p>
          <p class="span-txt">二、封面中的计划类别为：软科学研究、应用技术研究、交通信息化、高新技术研发、成果转化与推广、标准规范、其他。</p>
          <p class="span-txt">三、项目归口管理单位主要指集团直属各单位等有关单位。</p>
          <p class="span-txt">
            四、科技项目应以自主研发为主，提升自主研发能力，原则上不支持合作单位共同申报，因合理原因需联合申报的，合作单位仅限集团内部单位。</p>
          <p class="span-txt">
            五、申报项目的实施期限一般不超过2年，项目负责人不得超过3人，项目第一负责人原则上为第一申报单位的在职人员；同一申报人每人每年申报项目不得超过2项，申报人作为前三名项目负责人主持在研科技项目不得超过2项。</p>
          <p class="span-txt">六、建议书各填写内容，要求达到可行性论证和技术方案深度，可附必要文件资料。</p>
          <p class="span-txt">七、表格里的文字要求按默认的格式填写，若加小标题，请在默认格式上加粗。</p>
          <p class="span-txt">八、采用标准A4纸打印，纸质材料（一式2份）报送至集团科技信息部，电子版一并报送。</p>
        </div>
      </t-alert>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small">
            <template #title>
              {{ site_tag === 'jtt' ? '计划类别(必选)' : '申报信息' }}
            </template>
            <t-form-item label="计划类别：" labelWidth="0" labalAlign="top" name="projectCategory">
              <t-enhanced-table :selected-row-keys="selectedProjectCategoryRowKeys" hover
                @select-change="selectedProjectCategoryRowKeysChange"
                :tree="{ childrenKey: 'children', defaultExpandAll: false, expandTreeNodeOnClick: true }"
                ref="planCategoryTable" @row-click="onProjectCategoryRowClick" rowKey="id" :data="projectCategoryData"
                :columns="site_tag === 'jtt' ? projectCategoryColumns : projectCategoryColumns2">
                <template #categoryType="{ row }">
                  <t-tag v-if="row.categoryType === '1'" theme="primary" variant="light">计划</t-tag>
                  <t-tag v-else-if="row.categoryType === '2'" theme="success" variant="light">专题</t-tag>
                  <t-tag v-else-if="row.categoryType === '3'" theme="warning" variant="light">方向</t-tag>
                </template>
                <template #startDate="{ row }">
                  <template v-if="row.categoryType === '1'">
                    {{ row.startDate }}
                  </template>
                </template>
                <template #applyStatus="{ row }">
                  <div v-if="row.categoryType === '1'">
                    <t-tag
                      v-if="dayjs(dayjs().format('YYYY-MM-DD'), 'YYYY-MM-DD') >= dayjs(row.startDate, 'YYYY-MM-DD') && dayjs(dayjs().format('YYYY-MM-DD'), 'YYYY-MM-DD') <= dayjs(row.endDate, 'YYYY-MM-DD')"
                      theme="success" variant="light">正常申报
                    </t-tag>
                    <t-tag
                      v-else-if="dayjs(dayjs().format('YYYY-MM-DD'), 'YYYY-MM-DD') < dayjs(row.startDate, 'YYYY-MM-DD') && dayjs(dayjs().format('YYYY-MM-DD'), 'YYYY-MM-DD') <= dayjs(row.endDate, 'YYYY-MM-DD')"
                      theme="warning" variant="light">申报未开始只能暂存
                    </t-tag>
                    <t-tag
                      v-else-if="dayjs(dayjs().format('YYYY-MM-DD'), 'YYYY-MM-DD') > dayjs(row.endDate, 'YYYY-MM-DD')"
                      theme="danger" variant="light">已过期
                    </t-tag>
                  </div>
                </template>
                <template #endDate="{ row }">
                  <template v-if="row.categoryType === '1'">
                    {{ row.endDate }}
                  </template>
                </template>
              </t-enhanced-table>
            </t-form-item>
          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="6">
          <t-card class="step-card" size="small" title="基本信息">
            <t-form-item label="项目名称：" name="projectName">
              <t-tooltip theme="light">
                <template v-if="oldPorjectList.length > 0" #content>
                  <t-divider style="margin: 0"> 相似项目列表</t-divider>
                  <t-link v-for="(item, index) in oldPorjectList" :key="index"
                    @click="dialog.objId = item.projectId; dialog.header = item.projectName; dialog.open_project_detail = true"
                    hover="color" theme="primary">{{ item.projectName }}
                  </t-link>
                </template>
                <t-input @change="onProjectNameChange" clearable style="width: 390px"
                  v-model="formData.projectName"></t-input>
              </t-tooltip>
            </t-form-item>
            <t-form-item label="学科分类：" name="subjectClassification">
              <t-select clearable style="width: 390px" v-model="formData.subjectClassification"
                :options="dictTypes.subject_classification">
              </t-select>
            </t-form-item>

            <t-form-item label="项目类型：" name="projectType">
              <t-select @input-change="(val) => { formData.projectType = val }" filterable clearable
                style="width: 390px" v-model="formData.projectType" :options="dictTypes.project_type">
              </t-select>
            </t-form-item>
            <t-form-item label="申报日期：" name="declareDate">
              <t-date-picker clearable style="width: 390px" v-model="formData.declareDate"></t-date-picker>
            </t-form-item>
            <t-form-item label="项目开始时间：" name="startDate">
              <t-date-picker clearable style="width: 390px" v-model="formData.startDate"></t-date-picker>
            </t-form-item>
            <t-form-item label="项目结束时间：" name="endDate">
              <t-date-picker clearable style="width: 390px" v-model="formData.endDate"></t-date-picker>
            </t-form-item>
            <!--            <t-form-item label="关键词：" name="keyWord">-->
            <!--              <t-input clearable style="width: 390px" v-model="formData.keyWord" placeholder="关键词多个用符号间隔"/>-->
            <!--            </t-form-item>-->
            <t-form-item help="手输支持自定义创建" label="关键词：" name="keyWordList">
              <t-select v-model="formData.keyWordList" creatable filterable multiple placeholder="手输支持自定义创建"
                :options="dict.type.kjxm_key_word" style="width: 390px;" @create="createKeyWordOptions">
              </t-select>
            </t-form-item>
            <t-form-item label="建议经费总概算：" name="adviceFunding">
              <t-input-adornment append="万元">
                <t-input-number :decimal-places="2"
                  @keyup="() => { if (formData.adviceFunding) { formData.adviceFunding = Number((formData.adviceFunding || 0).toString().match(/^\d+(?:\.\d{0,2})?/)) } }"
                  :allowInputOverLimit="false" clearable style="width: calc(390px - 45px)"
                  v-model="formData.adviceFunding" theme="normal" :min="0"></t-input-number>
              </t-input-adornment>
            </t-form-item>
            <t-form-item :label="site_tag === 'jtt' ? '申请厅补助经费：' : '申请集团补助经费：'" name="subsidyFunding">
              <t-input-adornment append="万元">
                <t-input-number :decimal-places="2"
                  @keyup="() => { if (formData.subsidyFunding) { formData.subsidyFunding = Number((formData.subsidyFunding || 0).toString().match(/^\d+(?:\.\d{0,2})?/)) } }"
                  :allowInputOverLimit="false" clearable style="width: calc(390px - 45px)"
                  v-model="formData.subsidyFunding" theme="normal" :min="0"></t-input-number>
              </t-input-adornment>
            </t-form-item>
            <t-form-item v-if="site_tag === 'jt'" label="是否高速公路项目：" name="isRoadProject">
              <t-radio-group v-model="formData.isRoadProject"
                :options="[{ label: '是', value: '1' }, { label: '否', value: '0' }]"></t-radio-group>
            </t-form-item>
            <t-form-item v-if="site_tag === 'jt' && formData.isRoadProject === '1'" label="高速路段：" name="expresswayId">
              <t-cascader check-strictly @change="onExpresswayIdChange" style="width: 390px;" clearable filterable
                :keys="{ value: 'id', label: 'name' }" v-model="formData.expresswayId" :options="expresswayOptions">
              </t-cascader>
              <!-- <t-button v-if="formData.roadData" @click="drawerVisible=true" variant="text" class="t-button-link">
              <t-icon name="map-information-2" slot="icon"/>
              地图预览
              </t-button> -->
            </t-form-item>
            <!--            <t-form-item v-if="site_tag==='jt' && formData.isRoadProject==='1'" label="高速所在地：" name="locationId">-->
            <!--              <t-cascader style="width: 390px" clearable filterable :keys="{value:'id'}" v-model="formData.locationId" :options="locationOptions" placeholder="请选择所在地"></t-cascader>-->

            <!--            </t-form-item>-->
            <t-form-item v-if="site_tag === 'jt' && formData.isRoadProject === '1'" label="编号："
              name="sysExpressway.code">
              <t-input clearable :readonly="true" style="width: 390px" v-model="formData.sysExpressway.code"></t-input>
            </t-form-item>

          </t-card>
        </t-col>
        <t-col :span="6">
          <t-card class="step-card" size="small" title="项目联系人">
            <t-form-item label="姓名：" name="projectLinker.name">
              <t-select v-model="formData.projectLinker.name" creatable filterable @change="onLinkerNameChange"
                placeholder="请输入姓名" :loading="linkerLoading" @search="remoteProjectLinkerMethod"
                :options="projectLinkerOptions" @create="createProjectLinkerOptions" style="width: 390px" />
              <!--              <t-input style="width: 390px" clearable v-model="formData.projectLinker.name"-->
              <!--              ></t-input>-->
              <!--              <t-button @click="dialog.name=formData.projectLinker.name;dialog.type=2;dialog.openSearchMember=true" variant="text" class="t-button-link">-->
              <!--              <t-icon name="add" slot="icon"/>-->
              <!--              导入人员信息-->
              <!--              </t-button>-->
            </t-form-item>
            <t-form-item label="联系电话：" name="projectLinker.phone">
              <t-input style="width: 390px" placeholder="请输入手机号码" clearable
                v-model="formData.projectLinker.phone"></t-input>
            </t-form-item>
            <t-form-item label="通信地址：" name="projectLinker.address">
              <t-input style="width: 390px" clearable v-model="formData.projectLinker.address"></t-input>
            </t-form-item>
            <t-form-item label="电子信箱：" name="projectLinker.email">
              <t-input style="width: 390px" clearable v-model="formData.projectLinker.email"></t-input>
            </t-form-item>
            <t-form-item label="邮编：" name="projectLinker.postCode">
              <t-input style="width: 390px" clearable v-model="formData.projectLinker.postCode"></t-input>
            </t-form-item>
          </t-card>
        </t-col>
      </t-row>
      <!--      <t-row v-if="site_tag==='jt' && formData.isRoadProject==='1'" style="align-items: stretch;" :gutter="14">-->
      <!--        <t-col :span="12">-->
      <!--         -->
      <!--        </t-col>-->
      <!--      </t-row>-->
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="项目主要负责人">
            <t-row>
              <t-col :span="6">
                <t-form-item label="姓名：" name="projectLeader.name">
                  <t-select v-model="formData.projectLeader.name" creatable filterable @change="onLeaderNameChange"
                    placeholder="请输入姓名" :loading="leaderLoading" @search="remoteProjectLeaderMethod"
                    :options="projectLeaderOptions" @create="createProjectLeaderOptions" style="width: 390px" />
                </t-form-item>
                <t-form-item label="身份证号：" name="projectLeader.idCard">
                  <t-input style="width: 390px" @change="onIdCardChange" placeholder="请输入身份证号" clearable
                    v-model="formData.projectLeader.idCard"></t-input>
                </t-form-item>
                <t-form-item label="性别：" name="projectLeader.sex">
                  <t-select style="width: 390px" placeholder="请选择性别" :options="dictTypes.sys_user_sex"
                    v-model="formData.projectLeader.sex">
                  </t-select>
                </t-form-item>
                <t-form-item label="出生年月：" name="projectLeader.birthDate">
                  <t-date-picker placeholder="请选择生日" mode="month" v-model="formData.projectLeader.birthDate"
                    :disable-date="{
                      after: dayjs().endOf('month').add(-18, 'year').format()
                    }" style="width: 390px"></t-date-picker>
                </t-form-item>

                <t-form-item label="工作单位：" name="projectLeader.companyId">
                  <t-tree-select clearable filterable style="width: 390px" :treeProps="{ keys: { value: 'id' } }"
                    @change="(val, content) => { formData.projectLeader.company = content.node.data.label }"
                    v-model="formData.projectLeader.companyId" :data="deptMenuOptions"
                    placeholder="选择工作单位"></t-tree-select>
                </t-form-item>
                <t-form-item label="联系电话：" name="projectLeader.phone">
                  <t-input style="width: 390px" placeholder="请输入手机号码" clearable
                    v-model="formData.projectLeader.phone"></t-input>
                </t-form-item>
                <t-form-item label="通讯地址：" name="projectLeader.address">
                  <t-input style="width: 390px" clearable v-model="formData.projectLeader.address"></t-input>
                </t-form-item>
                <t-form-item label="电子信箱：" name="projectLeader.email">
                  <t-input style="width: 390px" clearable v-model="formData.projectLeader.email"></t-input>
                </t-form-item>
                <t-form-item label="邮编：" name="projectLeader.postCode">
                  <t-input style="width: 390px" clearable v-model="formData.projectLeader.postCode"></t-input>
                </t-form-item>
                <t-form-item label="毕业院校：" name="projectLeader.school">
                  <t-input style="width: 390px" clearable v-model="formData.projectLeader.school"></t-input>
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item label="学历：" name="projectLeader.education">
                  <t-select style="width: 390px" v-model="formData.projectLeader.education" clearable
                    placeholder="请选择学历" :options="dictTypes.education">
                  </t-select>
                </t-form-item>
                <t-form-item label="学位：" name="projectLeader.degree">
                  <t-select style="width: 390px" v-model="formData.projectLeader.degree" clearable placeholder="请选择学位"
                    :options="dictTypes.degree">
                  </t-select>
                </t-form-item>
                <t-form-item label="所学专业：" name="projectLeader.majorName">
                  <t-input style="width: 390px" clearable v-model="formData.projectLeader.majorName"></t-input>
                </t-form-item>
                <t-form-item label="现从事专业：" name="projectLeader.majorNowName">
                  <t-input style="width: 390px" clearable v-model="formData.projectLeader.majorNowName"></t-input>
                </t-form-item>
                <t-form-item label="职务：" name="projectLeader.duty">
                  <t-input style="width: 390px" clearable v-model="formData.projectLeader.duty"></t-input>
                </t-form-item>
                <t-form-item label="技术职称：" name="projectLeader.profTitId">
                  <t-tree-select clearable @change="onProfTitIdChange" filterable style="width: 390px"
                    :treeProps="{ keys: { value: 'id', label: 'name' }, valueMode: 'onlyLeaf' }"
                    v-model="formData.projectLeader.profTitId" :data="profTitOptions"
                    placeholder="技术职称"></t-tree-select>
                  <!--                    <t-input style="width: 390px" clearable v-model="formData.projectLeader.profTitId"-->
                  <!--                    ></t-input>-->
                </t-form-item>
                <t-form-item label="职称：" name="projectLeader.profTit">
                  <t-select disabled style="width: 390px" v-model="formData.projectLeader.profTit" clearable
                    placeholder="请选择职称" :options="dictTypes.prof_tit">
                  </t-select>
                </t-form-item>
                <t-form-item label="在本项目中承担的任务：" name="projectLeader.task">
                  <t-textarea style="width: 390px" clearable :autosize="{ minRows: 3 }"
                    v-model="formData.projectLeader.task" placeholder="请输入内容" />
                </t-form-item>
              </t-col>
            </t-row>
          </t-card>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button v-if="!getProjectId" theme="primary" type="submit">提交申请</t-button>
          <t-button v-else theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 立项背景和依据 -->
    <t-form ref="form" :key="activeForm" labelAlign="top" v-if="activeForm === 1" class="step-form" :data="formData2"
      @submit="onSubmit2" :rules="rules2" labelWidth="180px">
      <t-form-item name="background">
        <template #label>
          （一）研究背景：<span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
        </template>
        <tiny-mce-editor :key="activeForm" :maxlength="site_tag === 'jtt' ? maxlength : maxlength * 3"
          :textLength.sync="lengthLimitObj.background" v-model="formData2.background"></tiny-mce-editor>
      </t-form-item>
      <t-form-item name="goal">
        <template #label>
          （二）研究目的与意义：<span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
        </template>
        <tiny-mce-editor :key="activeForm" :maxlength="site_tag === 'jtt' ? maxlength : maxlength * 3"
          :textLength.sync="lengthLimitObj.goal" v-model="formData2.goal"></tiny-mce-editor>
      </t-form-item>
      <t-form-item name="actuality">
        <template #label>
          （三）国内外研究现状与评价：<span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
        </template>
        <tiny-mce-editor :key="activeForm" :maxlength="site_tag === 'jtt' ? maxlength : maxlength * 3"
          :textLength.sync="lengthLimitObj.actuality" v-model="formData2.actuality"></tiny-mce-editor>
      </t-form-item>
      <t-form-item name="literatures" :show-error-message="false" label="（四）主要参考文献：">
        <template slot="label">
          （四）主要参考文献：
          <t-alert style="margin-bottom: 14px" theme="info">
            <div slot="message">
              <p class="span-txt">
                * 期刊：主要作者.文献题名[J].刊名，出版年份，卷号(期号):起-止页码.
              </p>
              <p class="span-txt">
                * 专著：著者.书名[M].出版地:出版者，出版年:起-止页码.
              </p>
              <p class="span-txt">
                * 论文集：著者.文献题名[C].编者.论文集名.出版地:出版者，出版年:起-止页码.
              </p>
              <p class="span-txt">
                * 学位论文：作者.题名[D].保存地:保存单位，年份.
              </p>
              <p class="span-txt">
                * 报告：作者.文献题名[R].报告地:报告会主办单位，年份.
              </p>
              <p class="span-txt">
                * 专利：专利所有者.专利题名[P].专利国别:专利号，发布日期.
              </p>
              <p class="span-txt">
                * 国际、国家标准：标准代号，标准名称[S].出版地:出版者，出版年.
              </p>
              <p class="span-txt">
                * 报纸文章：作者.文献题名[N].报纸名，出版日期(版次).
              </p>
              <p class="span-txt">
                * 电子文献：[序号]作者.电子文献题名[文献类型/载体类型].电子文献的出版或可获得地址，发表或更新的期/引用日期(任选).
              </p>
            </div>
          </t-alert>
        </template>
        <project-background-literature phaseType="1" ref="project-background-literature" :projectId="getProjectId()"
          v-model="formData2.literatures" :editOpen="true"></project-background-literature>
        <!--          <tiny-mce-editor v-model="formData2.literature"></tiny-mce-editor>-->
      </t-form-item>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(0)" theme="primary" variant="base">上一步</t-button>
          <t-button theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 研究方案 -->
    <t-form ref="form" :key="activeForm" labelAlign="top" v-if="activeForm === 2" class="step-form" :data="formData3"
      @submit="onSubmit3" :rules="rules3">
      <t-form-item label="（一）研究内容、拟解决的关键问题、研究方法、技术路线及创新点" name="researchContent">
        <template #label>
          （一）研究内容、拟解决的关键问题、研究方法、技术路线及创新点<span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
        </template>
        <tiny-mce-editor :key="activeForm" :maxlength="site_tag === 'jtt' ? maxlength : maxlength * 3"
          :textLength.sync="lengthLimitObj.researchContent" v-model="formData3.researchContent"></tiny-mce-editor>
      </t-form-item>
      <t-form-item :showErrorMessage="false" label="（二）年度研究计划（包括起止年月、计划内容）" name="projectResearchPlan">
        <project-research-plan :disableDate="disableDate" ref="project-research-plan"
          v-model="formData3.projectResearchPlan" :projectId="getProjectId()" :editOpen="true"
          phaseType="1"></project-research-plan>
      </t-form-item>
      <t-form-item :showErrorMessage="false" label="（三）预期研究成果及表达形式" name="projectExpectResults">
        <template slot="label">
          （三）预期研究成果及表达形式 <span style="color: red">后续大纲、任务书阶段只能增加不能减少请认真填写！</span>
          <t-alert style="margin-bottom: 14px" theme="info">
            <div slot="message">
              <p class="span-txt">
                必须填写一条 成果类型为 研究报告的记录
              </p>
            </div>
          </t-alert>
        </template>
        <project-approach-expect-results phaseType="1" :projectId="getProjectId()" ref="project-approach-expect-results"
          v-model="formData3.projectExpectResults" :editOpen="true"></project-approach-expect-results>
      </t-form-item>
      <t-form-item label="（四）项目预期目标及经济、社会效益" name="expectedGoal">
        <template #label>
          （四）项目预期目标及经济、社会效益<span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
        </template>
        <tiny-mce-editor :maxlength="site_tag === 'jtt' ? maxlength : maxlength * 3"
          :textLength.sync="lengthLimitObj.expectedGoal" :key="activeForm"
          v-model="formData3.expectedGoal"></tiny-mce-editor>
      </t-form-item>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(1)" theme="primary" variant="base">上一步</t-button>
          <t-button theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 研究基础 -->
    <t-form ref="form" :key="activeForm" labelAlign="top" v-if="activeForm === 3" class="step-form" :data="formData4"
      @submit="onSubmit4" :rules="rules4">
      <t-form-item label="" name="achievement">
        <template slot="label">
          （一）与本项目有关的研究工作积累和已取得的研究工作成就（包括近期发表的与本项目有关的论文、出版的主要论著、获得的学术奖励、已完成和在研的研究项目等）
          <span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
          <t-alert style="margin-bottom: 14px" theme="info">
            <div slot="message">
              <p class="span-txt">
                * 论文要写明作者、题目、刊名、年份、卷（期）、页码
              </p>
              <p class="span-txt">
                * 专著要写明作者、书名、出版社、年份
              </p>
              <p class="span-txt">
                * 研究项目要写明名称、编号、项目来源、起止年月、负责或参加的情况以及与本项目的关系
              </p>
            </div>
          </t-alert>
        </template>
        <tiny-mce-editor :maxlength="site_tag === 'jtt' ? maxlength : maxlength * 3" :key="activeForm"
          :textLength.sync="lengthLimitObj.achievement" v-model="formData4.achievement"></tiny-mce-editor>
      </t-form-item>
      <t-form-item label="" name="conditions">
        <template slot="label">
          （二）项目依托工程情况及其它必要支撑条件（包括依托工程的概况，投资来源，工程进度与项目科研进度的配合情况）<span
            class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
        </template>
        <tiny-mce-editor :maxlength="site_tag === 'jtt' ? maxlength : maxlength * 3" :key="activeForm"
          :textLength.sync="lengthLimitObj.conditions" v-model="formData4.conditions"></tiny-mce-editor>
      </t-form-item>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(2)" theme="primary" variant="base">上一步</t-button>
          <t-button theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 单位信息 -->
    <div class="step-form" v-if="activeForm === 4">
      <project-unit ref="project-unit" v-model="formData5.unitList" :adviceFunding="adviceFunding"
        :projectId="getProjectId()" :editOpen="true" phaseType="1"></project-unit>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(3)" theme="primary" variant="base">上一步</t-button>
          <t-button theme="primary" @click="onSubmit5">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </div>
    <!-- 研究人员 -->
    <div class="step-form" v-if="activeForm === 5">
      <project-member :isOldProject="formData.isOldProject" :show-tip="true" v-model="formData6.memberList"
        :projectId="getProjectId()" :editOpen="true" phaseType="1"></project-member>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(4)" theme="primary" variant="base">上一步</t-button>
          <t-button theme="primary" @click="onSubmit6" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </div>
    <!-- 经费预算 -->
    <div class="step-form" v-if="activeForm === 6">
      <t-alert style="margin-bottom: 14px" theme="info" title="填表说明：">
        <div slot="message">
          <p class="span-txt">
            1、项目申报时，只需填列项目经费来源和支出的预算数；在项目结题验收时，项目经费来源和支出的预算和决算数均需埴列。
          </p>
          <p class="span-txt">2、“其他”一栏是在与上几栏内容均不相同时具体填写。</p>
          <p class="span-txt">3、直接费用</p>
          <p class="span-txt">（1）设备费：是指在项目研究开发过程中购置或试制专用仪器设备，对现有仪器设备进行升级改造，以及租赁外单位仪器设备而发生的费用。厅拨经费要严格控制设备购置费支出。</p>
          <p class="span-txt">（2）材料费：是指在项目研究开发过程中消耗的各种原材料、辅助材料等低值易耗品的采购及运输、装卸、整理等费用。</p>
          <p class="span-txt">（3）测试化验实验加工费：是指在项目研究开发过程中支付给外单位（包括项目承担单位内部独立经济核算单位）的检验、测试、化验、实验及加工等费用。</p>
          <p class="span-txt">（4）燃料动力费：是指在项目研究开发过程中相关大型仪器设备、专用科学装置等运行发生的可以单独计量的水、电、气、燃料消耗费用等。</p>
          <p class="span-txt">（5）差旅费：是指在项目研究开发过程中开展科学实验（试验）、科学考察、业务调研、学术交流等所发生的外埠差旅费、市内交通费用等。差旅费的开支标准应当按照国家有关规定执行。</p>
          <p class="span-txt">
            （6）会议费：是指在项目研究开发过程中为组织开展学术研讨、审查、咨询以及协调项目等活动而发生的会议费用。项目承担单位应当按照国家有关规定，严格控制会议规模、会议数量、会议开支标准和会期。</p>
          <p class="span-txt">
            （7）国际合作与交流费：是指在项目研究开发过程中项目研究人员出国及外国专家来华工作的费用。国际合作与交流费应当严格执行国家外事经费管理的有关规定。项目发生国际合作与交流费时，应当事先报经项目承担单位审核同意。</p>
          <p class="span-txt">
            （8）出版／文献／信息传播／知识产权事务／印刷费：是指在项目研究开发过程中，需要支付的出版费、资料费、印刷费、翻译费、专用软件购买费、数据购买和调查费、文献检索费、专业通信费、专利申请及其他知识产权事务等费用。
          </p>
          <p class="span-txt">（9）劳务费：是指在项目研究开发过程中支付给项目组成员中没有工资性收入的相关人员（如在校研究生）和项目组临时聘用人员等的劳务性费用。</p>
          <p class="span-txt">（10）专家咨询费：是指在项目研究开发过程中支付给临时聘请的咨询专家的费用。</p>
          <p class="span-txt">4、间接费用</p>
          <p class="span-txt">间接费用总额使用分段超额累退比例法计算和控制，按照不超过直接费用扣除设备购置费后的一定比例核定，具体比例如下：500 万元及以下部分不超过20％；超过500 万元至1000
            万元的部分不超过13％；超过1000万元的部分不超过10％。</p>
          <p class="span-txt">（1）管理费：是指在项目研究开发过程中对使用本单位现有仪器设备及房屋，日常水、电、气、暖消耗，以及其他有关管理费用的补助支出。</p>
          <p class="span-txt">（2）绩效支出：是指承担项目研究任务的单位为提高科研工作绩效安排的相关支出。有财政拨款补助的单位安排的绩效支出不得超过直接费用扣除设备购置费后的5％。</p>
        </div>
      </t-alert>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <project-budget v-model="formData7" :fundingObj="fundingObj" :projectId="getProjectId()" :editOpen="true"
            phaseType="1"></project-budget>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(5)" theme="primary" variant="base">上一步
          </t-button>
          <t-button theme="primary" @click="onSubmit7()" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </div>
    <!-- 附件信息 -->
    <div class="step-form" v-if="activeForm === 7">
      <t-row>
        <t-col :span="12">
          <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
            <template #id="{ row, rowIndex }">
              {{ rowIndex + 1 }}
            </template>
            <template #op="{ row }">
              <file-upload tips="限制pdf、图片" accept="application/pdf,image/*" v-model="row.fileIds"
                :moduleKey="row.moduleKey" :fileList="row.fileLists" :multiple="true">
                <t-button variant="outline">
                  <t-icon name="cloud-upload" slot="icon" />
                  点击上传
                </t-button>
              </file-upload>
            </template>
            <template #c1="{ row }">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
          </t-table>
          <div style="color: red;">注意:请在 {{ endDateOnSubmit }} 23:59:59 前点击提交，否则会导致项目申报超期!</div>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(6)" theme="primary" variant="base">上一步
          </t-button>
          <t-button theme="primary" @click="onSubmit8(1)" type="submit">{{ check() ? '暂存' : '确认修改' }}</t-button>
          <t-tooltip v-if="check()" :content="formData.isOldProject === '1' ? '提交后不会进入审批流程' : '提交后不可再编辑会进入审批流程'">
            <t-button :disabled="isCommit" theme="primary" @click="onSubmit8(2)" type="submit">
              {{ formData.isOldProject === '1' ? '提交' : '提交到单位管理员' }}
            </t-button>
          </t-tooltip>

        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </div>
    <project-detail-dialog :header="dialog.header" :hide-info="true" :objId="dialog.objId"
      :visible.sync="dialog.open_project_detail" v-if="dialog.open_project_detail"></project-detail-dialog>

  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import { getDictList } from "@/api/system/dict/data";
import TinyMceEditor from "@/components/TinyMceEditor/index.vue";
import ProjectResearchPlan from "./components/project-research-plan.vue";
import ProjectUnit from "./components/project-unit.vue";
import ProjectMember from "./components/project-member.vue";
import ProjectBudget from "./components/project-budget.vue";
import ProjectBackgroundLiterature from "./components/project-background-literature.vue";
import ProjectApproachExpectResults from "./components/project-approach-expectResults.vue";
import ProjectDetailDialog from "./components/project-detail-dialog.vue";
import FileUpload from "@/components/FileUpload/index.vue"
import { getFiles } from "@/api/common";
import { TODAY } from '@/utils/date';
import { getIdCardBirthday, getIdCardAge } from '@/utils/common';
import dayjs from "dayjs";


export default {
  name: "project_apply",
  dicts: ['kjxm_key_word'],
  components: {
    TinyMceEditor,
    ProjectResearchPlan,
    ProjectUnit,
    ProjectBudget,
    ProjectMember,
    FileUpload,
    ProjectBackgroundLiterature,
    ProjectApproachExpectResults,
    ProjectDetailDialog,

  },
  data () {
    return {
      file_domain: VITE_FILE_DOMAIN,
      drawerVisible: false,
      map: null,
      coordinate: "",
      dialog: {
        data: [],
        data2: [],
        openSearchMember: false,
        name: '',
        type: 1,
      },
      leaderLoading: false,
      linkerLoading: false,
      endDateOnSubmit: null,
      projectLinkerOptions: [],
      projectLeaderOptions: [],
      applyLoading: false,
      maxlength: 2000,
      lengthLimitObj: {
        background: 0,
        goal: 0,
        actuality: 0,
        researchContent: 0,
        expectedGoal: 0,
        achievement: 0,
        conditions: 0
      },
      fundingObj: { subsidyFunding: 0, adviceFunding: 0 },
      disableDate: {},
      adviceFunding: 0,
      subsidyFunding: 0,
      tinymceFlag: 1,
      oldUser: null,
      dayjs,
      site_tag: import.meta.env.VITE_SITE_TAG,
      projectCategoryData: [],
      projectCategoryColumns: [
        {
          colKey: "name",
          title: "类别名称",
        },
        {
          colKey: 'row-select',
          type: 'single',
          title: "选择",
          width: 64,
          checkProps: ({ row }) => ({ disabled: row.children && row.children.length > 0 }),
        },
        {
          colKey: "categoryType",
          title: "类型",
          align: "center",
          width: 100
        },
        {
          colKey: "startDate",
          title: "申报开始时间",
          align: "center",
          width: 200
        },
        {
          colKey: "endDate",
          title: "申报结束时间",
          align: "center",
          width: 200
        },
        {
          colKey: "declareEndDate",
          title: "申报单位审批截止时间",
          align: "center",
          width: 200
        },
        {
          colKey: "manageEndDate",
          title: "归口单位推荐截止时间",
          align: "center",
          width: 200
        },
        {
          colKey: "applyStatus",
          title: "申报状态",
          align: "center",
          width: 200
        },
        {
          colKey: 'note',
          title: "描述",
          ellipsis: true
        },
      ],
      projectCategoryColumns2: [
        // {
        //   colKey: "name",
        //   title: "类别名称",
        // },
        // {
        //   colKey: 'row-select',
        //   type: 'single',
        //   title: "选择",
        //   width: 64,
        //   checkProps: ({row}) => ({disabled: row.children && row.children.length > 0}),
        // },
        // {
        //   colKey: "categoryType",
        //   title: "类型",
        //   align: "center",
        //   width: 100
        // },
        {
          colKey: "startDate",
          title: "申报开始时间",
          align: "center",
          width: 200
        },
        {
          colKey: "endDate",
          title: "申报结束时间",
          align: "center",
          width: 200
        },
        {
          colKey: "declareEndDate",
          title: "申报单位审批截止时间",
          align: "center",
          width: 200
        },
        {
          colKey: "manageEndDate",
          title: "归口单位推荐截止时间",
          align: "center",
          width: 200
        },
        {
          colKey: "applyStatus",
          title: "申报状态",
          align: "center",
          width: 200
        },
        {
          colKey: 'note',
          title: "描述",
          ellipsis: true
        },
      ],
      projectFileData: [
        {
          id: 1,
          c1: "查新报告",
          c2: "是",
          moduleKey: "projectCXBG",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 2,
          c1: "归口管理单位科研诚信承诺书(模版)",
          c2: "是",
          c3: 'view/模板/归口管理单位科研诚信承诺书.pdf',
          fileIds: [],
          fileLists: [],
          moduleKey: "projectCNS",
          require: true,
        },
        {
          id: 3,
          c1: "项目组科研诚信承诺书(模版)",
          c2: "是",
          c3: 'view/模板/项目组科研诚信承诺书.pdf',
          fileIds: [],
          fileLists: [],
          moduleKey: "projectTeamCNS",
          require: true,
        },
        {
          id: 6,
          c1: "其他",
          c2: "否",
          moduleKey: "projectQT",
          fileIds: [],
          fileLists: [],
          require: false,
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "left",
        },
      ],
      selectedProjectCategoryRowKeys: [],
      isCommit: false,
      profTitOptions: [],
      menuOptions: [],
      deptMenuOptions: [],
      // selectedResearchPlanRowKeys: [],
      selectedUnitRowKeys: [],
      selectedMemberRowKeys: [],
      selectedMember1RowKeys: [],
      formData7: {
        budgetType: "1",
        phaseType: '1',
        inTbBudget: null,
        inZcBudget: null,
        inZcQtczbkBudget: null,
        inZcDwBudget: null,
        inZcQtBudget: null,
        outTbSbBudget: null,
        outZcSbBudget: null,
        outTbSzsbBudget: null,
        outZcSzsbBudget: null,
        outTbSbzzBudget: null,
        outZcSbzzBudget: null,
        outTbClBudget: null,
        outZcClBudget: null,
        outTbSyjgBudget: null,
        outZcSyjgBudget: null,
        outTbRldlBudget: null,
        outZcRldlBudget: null,
        outTbClvBudget: null,
        outZcClvBudget: null,
        outTbHyBudget: null,
        outTbGjhzBudget: null,
        outZcGjhzBudget: null,
        outTbCbBudget: null,
        outZcCbBudget: null,
        outTbLwBudget: null,
        outZcLwBudget: null,
        outTbZjzxBudget: null,
        outZcZjzxBudget: null,
        outTbQtBudget: null,
        outZcQtBudget: null,
        outTbGlBudget: null,
        outZcGlBudget: null,
        outTbJxzcBudget: null,
        outZcJxzcBudget: null,
        outZcHyBudget: null
      },
      data8: [],
      columns7: [],
      columns9: [],
      data3: [],
      data7: [],
      taskId: null,
      tabValue: "0",
      activeForm: null,
      dictTypes: {},
      wordData: 0,
      formData2: {
        background: '',
        goal: '',
        actuality: '',
        literature: '',
        literatures: [],
        projectId: null,
      },
      rules2: {
        background: [
          {
            required: true,
            message: "研究背景不能为空",
          },
        ],
        goal: [
          {
            required: true,
            message: "研究目的与意义不能为空",
          },
        ],
        actuality: [
          {
            required: true,
            message: "国内外研究现状与评价不能为空",
          },
        ],
        // literature: [
        //   {
        //     required: true,
        //     message: "主要参考文献不能为空",
        //   },
        // ],
        literatures: [
          { required: true, validator: (val) => val && val.length, message: "主要参考文献不能为空", type: "error" }
        ]
      },
      expresswayOptions: [],
      formData: {
        keyWordList: [],
        expresswayId: null,
        locationId: null,
        isRoadProject: '0',
        roadData: '',
        startPointX: '',
        startPointY: '',
        endPointX: '',
        endPointY: '',
        sysExpressway: {
          code: '',
          startNum: '',
          endNum: '',
        },
        // startNum: '',
        // endNum: '',
        projectName: '',
        projectCategory: '',
        platformType: '',
        subjectClassification: '',
        projectType: '',
        declareDate: TODAY,
        startDate: '',
        endDate: '',
        dateRange: [],
        keyWord: '',
        adviceFunding: null,
        subsidyFunding: null,
        // projectStatus: 1, // 暂存传1，提交传2
        isOldProject: '0',
        projectLinker: {
          id: null,
          name: '',
          phone: '',
          email: '',
          postCode: '',
        },
        projectLeader: {
          id: null,
          name: '',
          sex: '',
          birthDate: '',
          phone: '',
          address: '',
          email: '',
          postCode: '',
          profTit: '',
          school: '',
          majorName: '',
          degree: '',
          duty: '',
          // departmentId: null,
          companyId: null,
          company: '',
          profTitId: null,
          workDepartment: '',
          majorNowName: '',
          task: '',
          type: '1',
          isAssist: '0',
          idCard: '',
          education: '',
        },
        projectTeam: {
          totalCount: 0,
          highCount: 0,
          middleCount: 0,
          primaryCount: 0,
          postgraduate: 0,
          auxilian: 0,
        },
        version: '2015'
      },
      rules: {
        keyWordList: [{ required: true, validator: (val) => val && val.length, message: "关键词不能为空", type: "error" }],
        isRoadProject: [
          {
            required: true,
            message: "不能为空",
          },
        ],
        expresswayId: [
          {
            required: true,
            message: "高速路段不能为空",
          },
        ],
        locationId: [
          {
            required: true,
            message: "所在地不能为空",
          },
        ],
        'sysExpressway.startNum': [
          {
            required: true,
            message: "起点桩号不能为空",
          },
        ],
        'sysExpressway.endNum': [
          {
            required: true,
            message: "终点桩号不能为空",
          },
        ],
        'sysExpressway.code': [
          {
            required: true,
            message: "编号不能为空",
          },
        ],
        projectName: [
          {
            required: true,
            message: "项目名称不能为空",
          },
        ],
        projectCategory: [
          { required: true, message: "计划类别不能为空", type: "error" }
        ],
        platformType: [
          {
            required: true,
            message: "平台类型不能为空",
          },
        ],
        subjectClassification: [
          {
            required: true,
            message: "学科分类不能为空",
          },
        ],
        projectType: [
          {
            required: true,
            message: "项目类型不能为空",
          },
        ],
        adviceFunding: [
          {
            required: true,
            message: "建议经费总概算不能为空",
          },
        ],
        subsidyFunding: [
          {
            required: true,
            message: "申请补助经费不能为空",
          },
        ],
        dateRange: [
          { required: true, validator: (val) => val && val.length, message: "项目时间不能为空", type: "error" }
        ],
        keyWord: [
          {
            required: true,
            message: "关键词不能为空",
          },
        ],
        declareDate: [
          {
            required: true,
            message: "申报时间不能为空",
          },
        ],
        startDate: [
          {
            required: true,
            message: "项目开始时间不能为空",
          },
          {
            validator: (val) => {
              if (val && this.formData.declareDate) {
                const startTime = new Date(val).getTime()
                const endTime = new Date(this.formData.declareDate).getTime()
                return startTime >= endTime;
              }
              return true;
            }, message: "项目开始时间一定大于项目申报日期", type: "error"
          },
        ],
        endDate: [
          {
            required: true,
            message: "项目结束时间不能为空",
          },
          {
            validator: (val) => {
              if (val && this.formData.startDate) {
                const startTime = new Date(this.formData.startDate).getTime()
                const endTime = new Date(val).getTime()
                return startTime <= endTime;
              }
              return true;
            }, message: "项目开始时间不能大于结束时间", type: "error"
          },
        ],
        'projectLinker.name': [
          {
            required: true,
            message: "联系人姓名不能为空",
          },
        ],
        'projectLinker.phone': [
          {
            required: true,
            message: "联系人电话不能为空",
          },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "联系人电话请输入正确的手机号码",
          },
        ],
        'projectLinker.address': [
          {
            required: true,
            message: "联系人通讯地址不能为空",
          },
        ],
        'projectLinker.email': [
          {
            required: true,
            message: "联系人邮箱不能为空",
          },
          { email: { ignore_max_length: true }, message: '请输入正确的邮箱地址' }
        ],
        'projectLinker.postCode': [
          {
            required: true,
            message: "联系人邮编不能为空",
          },
        ],
        // 'projectLeader.workDepartment': [
        //   {
        //     required: true,
        //     message: "项目主要负责人工作单位不能为空",
        //   },
        // ],
        'projectLeader.companyId': [
          {
            required: true,
            message: "项目主要负责人工作单位不能为空",
          },
        ],
        'projectLeader.name': [
          {
            required: true,
            message: "项目主要负责人姓名不能为空",
          },
        ],
        'projectLeader.sex': [
          {
            required: true,
            message: "项目主要负责人性别不能为空",
          },
        ],
        'projectLeader.birthDate': [
          {
            required: true,
            message: "项目主要负责人生日不能为空",
          },
        ],
        'projectLeader.idCard': [
          {
            required: true,
            message: "项目主要负责人身份证号不能为空",
          },
          {
            message: "项目主要负责人身份证号不正确",
            pattern: /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/,
          },
        ],
        'projectLeader.phone': [
          {
            required: true,
            message: "项目主要负责人联系电话不能为空",
          },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "项目主要负责人联系电话请输入正确的手机号码",
          },
        ],
        'projectLeader.address': [
          {
            required: true,
            message: "项目主要负责人地址不能为空",
          },
        ],
        'projectLeader.email': [
          {
            required: true,
            message: "项目主要负责人邮箱不能为空",
          },
          { email: { ignore_max_length: true }, message: '请输入正确的邮箱地址' }
        ],
        'projectLeader.postCode': [
          {
            required: true,
            message: "项目主要负责人邮编不能为空",
          },
        ],
        'projectLeader.school': [
          {
            required: true,
            message: "项目主要负责人毕业院校不能为空",
          },
        ],
        'projectLeader.education': [
          {
            required: true,
            message: "项目主要负责人学历不能为空",
          },
        ],
        'projectLeader.degree': [
          {
            required: true,
            message: "项目主要负责人学位不能为空",
          },
        ],
        'projectLeader.majorName': [
          {
            required: true,
            message: "项目主要负责人所学专业不能为空",
          },
        ],
        'projectLeader.majorNowName': [
          {
            required: true,
            message: "项目主要负责人现从事专业不能为空",
          },
        ],
        'projectLeader.task': [
          {
            required: true,
            message: "项目主要负责人在本项目中承担的任务不能为空",
          },
        ],
        'projectLeader.duty': [
          {
            required: true,
            message: "项目主要负责人职务不能为空",
          },
        ],
        'projectLeader.profTit': [
          {
            required: true,
            message: "项目主要负责人职称不能为空",
          },
        ],
        'projectLeader.profTitId': [
          {
            required: true,
            message: "项目主要负责人技术职称不能为空",
          },
        ],
        'projectTeam.totalCount': [
          { required: true, validator: (val) => val >= 0, message: "大于等于0", type: "error" }
        ],
        'projectTeam.highCount': [
          { required: true, validator: (val) => val >= 0, message: "大于等于0", type: "error" }
        ],
        'projectTeam.middleCount': [
          { required: true, validator: (val) => val >= 0, message: "大于等于0", type: "error" }
        ],
        'projectTeam.primaryCount': [
          { required: true, validator: (val) => val >= 0, message: "大于等于0", type: "error" }
        ],
        'projectTeam.postgraduate': [
          { required: true, validator: (val) => val >= 0, message: "大于等于0", type: "error" }
        ],
        'projectTeam.auxilian': [
          { required: true, validator: (val) => val >= 0, message: "大于等于0", type: "error" }
        ]
      },
      projectCategoryOptions: [],
      formData3: {
        researchContent: '',
        expectedResults: '',
        expectedGoal: '',
        projectResearchPlan: [],
        projectExpectResults: []
      },
      rules3: {
        researchContent: [
          {
            required: true,
            message: "研究内容不能为空",
          },
        ],
        projectExpectResults: [
          { required: true, validator: (val) => val.length > 0, message: "预期研究成果及表达形式不能为空", type: "error" }
        ],
        expectedGoal: [
          {
            required: true,
            message: "项目预期目标及经济、社会效益不能为空",
          },
        ],
        projectResearchPlan: [
          { required: true, validator: (val) => val.length > 0, message: "年度研究计划不能为空", type: "error" }
        ]
      },
      formData4: {
        achievement: '',
        conditions: '',
      },
      rules4: {
        achievement: [
          {
            required: true,
            message: "研究工作积累和已取得的研究工作成就不能为空",
          },
        ],
        conditions: [
          {
            required: true,
            message: "项目依托工程情况及其它必要支撑条件不能为空",
          },
        ],
      },
      formData5: {
        unitList: []
      },
      formData6: {
        memberList: []
      },
      oldPorjectList: [],
      locationOptions: []
    }
  },
  watch: {
    activeForm: {
      immediate: true,
      handler (val) {
        // this.$refs.form?.clearValidate();
        this.oldUser = null;
        // document.getElementsByClassName("t-layout__content").scrollTop;
        const targetEle = document.getElementsByClassName("base-container")[0]
        if (targetEle) {
          const { pos, top } = targetEle.style;
          targetEle.style.position = 'relative';
          targetEle.style.top = '-100px';
          targetEle.scrollIntoView({ behavior: 'smooth', block: 'start', inline: "nearest" });
          targetEle.style.top = top;
          targetEle.style.position = pos;
        }
        // document.getElementById("main").scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"})
      }
    }
  },
  async created () {
    this.formData.isOldProject = this.$route.query.isOldProject || '0';
    this.formData.projectStatus = this.$route.query.projectStatus || '0';
    if (this.formData.isOldProject === '1') {
      this.projectFileData.push({
        id: 4,
        c1: "已盖章申报书",
        c2: "审批通过之后，走完盖章流程后上传。(当前阶段非必需)",
        fileIds: [],
        fileLists: [],
        moduleKey: "projectSBS",
        require: false,
      })
    }
    // 查新报告非必填
    if (this.site_tag === 'jt') {
      this.$set(this.projectFileData[0], 'c2', '否')
      this.$set(this.projectFileData[0], 'require', false)
      // this.projectFileData.splice(3,0,{
      //   id: 5,
      //   c1: "集团各直属单位（即项目归口管理单位）应对项目申报材料进行审查并提出书面审查意见，未经审查项目不得申报，需盖公章。",
      //   c2: "归口管理单位审批通过后上传。后续点击详情-附件上传。(当前阶段非必需)",
      //   fileIds: [],
      //   fileLists: [],
      //   moduleKey: "projectSMSCYJ",
      //   require: false,
      // })
      let item = this.projectFileData.splice(0, 1);
      this.projectFileData.splice(2, 0, item[0])
      this.projectFileData.shift();
      this.projectFileData.shift();
    }
    const taskId = this.$route.params && this.$route.params.taskId;
    if (!taskId) {
      this.$message.error("任务id丢失返回项目");
      this.$router.push("/kjxm/pm/project-my");
      return false;
    }
    await Promise.all([this.getDataTypes(), this.getDeptTreeSelect(this.$store.state.user.deptId), this.getProfTitTreeSelect(),
    this.getPlanCategoryTreeSelect(), this.getExpresswayTreeSelect(), this.getLocationTreeSelect()]);

    this.taskId = taskId;
    const activeForm = Number(sessionStorage.getItem(`${taskId}-activeForm`)) || 0;
    // this.activeForm = activeForm;
    // this.applyLoading = true;
    if (sessionStorage.getItem(`${this.taskId}-projectId`)) {
      this.$api.kjxm.project.get(sessionStorage.getItem(`${this.taskId}-projectId`)).then(response => {
        // 根据当前项目限定时间
        this.disableDate = {
          before: dayjs(response.data.startDate, "YYYY-MM-DD").endOf('month').subtract(1, 'month').format(),
          after: dayjs(response.data.endDate, "YYYY-MM-DD").endOf('month').subtract(0, 'month').format(),
        }
        this.adviceFunding = response.data.adviceFunding;
        this.subsidyFunding = response.data.subsidyFunding;
        this.fundingObj = {
          adviceFunding: response.data.adviceFunding,
          subsidyFunding: response.data.subsidyFunding
        }
        this.onCurChanged(activeForm, 0);
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    } else {
      this.activeForm = activeForm;
      this.applyLoading = false;
    }

    this.$api.kjxm.project.getById(1660720545908).then(res => {
      this.endDateOnSubmit = res.data.endDate
    }).catch(e => {
      this.$message(e.toString())
    })
  },
  mounted () {


  },
  beforeDestroy () {
    this.applyLoading = false;
  },
  methods: {
    check () {
      if (this.formData.projectStatus === '5' || this.formData.projectStatus === '9') {
        return false
      }
      return true
    },
    onExpresswayIdChange (val, content) {
      // 1. 根据桩号拿到经纬度
      // 2. 根据桩号拿到动态分段
      // this.formData.startNum = content.node.data.startNum;
      // this.formData.endNum = content.node.data.endNum;



      this.$set(this.formData.sysExpressway, 'startNum', content.node.data.startNum)
      this.$set(this.formData.sysExpressway, 'endNum', content.node.data.endNum)
      this.$set(this.formData.sysExpressway, 'code', content.node.data.code)

    },

    onProjectNameChange (val) {
      if (val) {
        this.$api.kjxm.project.getSimilarProjectByName({ keyWord: val }).then(res => {
          this.oldPorjectList = res.data || [];

        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }
    },
    createKeyWordOptions (value) {
      this.dict.type.kjxm_key_word.push({
        label: `${value}`,
        value,
      });
    },
    addMemberData (row, type) {
      // if (Object.prototype.hasOwnProperty.call(row, "idCard")) {
      //   delete row.idCard;
      // }
      // if (Object.prototype.hasOwnProperty.call(row, "phone")) {
      //   delete row.phone;
      // }
      if (type === 1) {
        this.formData.projectLeader = row;
      } else {
        this.formData.projectLinker = row
      }
    },
    onLinkerNameChange (val, content) {
      const index = this.projectLinkerOptions.findIndex(val => content.option?.id === val.id)
      this.projectLinkerOptions[index].label = this.projectLinkerOptions[index].name;
      this.$set(this.projectLinkerOptions, index, this.projectLinkerOptions[index])
      const oldId = this.formData.projectLinker.id;
      this.$set(this.formData, "projectLinker", this.projectLinkerOptions[index])
      this.formData.projectLinker.id = oldId;
      // Object.assign(this.formData.projectLinker,content.option)
    },
    onLeaderNameChange (val, content) {
      const index = this.projectLeaderOptions.findIndex(val => content?.option?.id === val.id)
      this.projectLeaderOptions[index].label = this.projectLeaderOptions[index].name;
      this.$set(this.projectLeaderOptions, index, this.projectLeaderOptions[index])
      // Object.assign(this.formData.projectLeader, content.option)
      const oldId = this.formData.projectLeader.id;
      this.$set(this.formData, "projectLeader", this.projectLeaderOptions[index])
      this.formData.projectLeader.id = oldId;
    },
    onProfTitIdChange (val, content) {
      this.formData.projectLeader.profTit = content.node.data.level;
    },
    onOldUser () {
      Object.assign(this.formData.projectLeader, this.oldUser)
    },
    onIdCardChange (val) {
      const birthday = getIdCardBirthday(val);
      if (birthday !== "") {
        this.formData.projectLeader.birthDate = birthday.slice(0, 7);
        this.$api.kjxm.project.findProjectMember(val).then(response => {
          this.oldUser = response.data;
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }
    },
    deptChange (val) {
      this.formData.projectLeader.workDepartment = val;
    },
    selectedProjectCategoryRowKeysChange (val) {
      this.selectedProjectCategoryRowKeys = val;
      [this.formData.projectCategory] = val;
    },
    onProjectCategoryRowClick ({ row, e }) {
      // const el1 = e.currentTarget
      // const el2 = e.target
      // const rowData = this.$refs.planCategoryTable.getData(row.id);
      // this.$refs.planCategoryTable.toggleExpandData(rowData);
      if (!(row.children && row.children.length > 0)) {
        this.selectedProjectCategoryRowKeys = [row.id];
        this.formData.projectCategory = row.id;
      }
      // if (el2.toString().includes("SVGSVGElement")) {
      //   this.$refs.planCategoryTable.toggleExpandData(rowData);
      // }
    },
    getExpresswayTreeSelect () {
      return this.$api.system.expressway.list().then(
        (res) => {
          this.expresswayOptions = this.handleTree(res.data, "id");
        }).catch((e) => {
          this.$message.error(e.toString());
        });
    },
    getLocationTreeSelect () {
      return this.$api.system.location.treeselect().then(response => {
        this.locationOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getPlanCategoryTreeSelect () {
      return this.$api.kjxm.project.planCategoryEnableList().then(
        (res) => {
          this.projectCategoryData = this.handleTree(res.data, "id");
          this.$refs.planCategoryTable?.resetData(this.projectCategoryData);
          // 集团默认选第一个
          if (this.site_tag === 'jt' && this.projectCategoryData.length > 0) {
            this.formData.projectCategory = this.projectCategoryData[0].id;
          }
        }).catch((e) => {
          this.$message.error(e.toString());
        });
    },
    getProfTitTreeSelect () {
      return this.$api.system.profTit.list().then(response => {
        // this.profTitOptions = response.data;
        this.profTitOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeptTreeSelect () {
      return this.$api.system.dept.treeSelectAll().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getQualification () {
      this.$api.kjxm.project.qualification().then(response => {
        this.unCommit = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    close () {
      this.applyLoading = false;
      setTimeout(() => {
        this.$tab.closeOpenPage({ path: this.$route.meta.activeMenu || "/kjxm/apply/project-my" });
      }, 1000)
    },
    onCurChanged (cur, pre) {
      if (Number(cur) !== 0) {
        if (!sessionStorage.getItem(`${this.taskId}-projectId`)) {
          this.applyLoading = false;
          this.$message.error("基本信息还未提交")
          return false;
        }
      }
      if (!this.applyLoading) {
        this.applyLoading = true;
      }
      // 根据不同的activeForm 复查数据
      if (Number(cur) === 0) {
        if (sessionStorage.getItem(`${this.taskId}-projectId`)) {
          const projectId = Number(sessionStorage.getItem(`${this.taskId}-projectId`));
          this.$api.kjxm.project.get(projectId).then(response => {
            response.data.projectLeader = response.data.projectLeader ? response.data.projectLeader : this.formData.projectLeader;
            Object.assign(this.formData, response.data);
            this.formData.keyWordList = response.data.keyWord.split(",").filter(item => item !== '')
            if (response.data.projectCategory) {
              this.selectedProjectCategoryRowKeys = [response.data.projectCategory];
            }
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
            this.applyLoading = false;
            // this.formData.dateRange = [response.data.startDate, response.data.endDate];
            // this.formData.keyWord = response.data.keyWord.split(",").filter(item=> item !== '');
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
          this.applyLoading = false;
        }

      } else if (Number(cur) === 1) {
        if (sessionStorage.getItem(`${this.taskId}-backgroundId`)) {
          const backgroundId = Number(sessionStorage.getItem(`${this.taskId}-backgroundId`));
          this.$api.kjxm.project.backgroundGet(backgroundId).then(response => {
            this.formData2 = response.data;
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
          this.applyLoading = false;
        }

      } else if (Number(cur) === 2) {
        if (sessionStorage.getItem(`${this.taskId}-approachId`)) {
          const approachId = Number(sessionStorage.getItem(`${this.taskId}-approachId`));
          this.$api.kjxm.project.approachGet(approachId).then(response => {
            this.formData3 = response.data;
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
          this.applyLoading = false;
        }
      } else if (Number(cur) === 3) {
        if (sessionStorage.getItem(`${this.taskId}-basicstudyId`)) {
          const basicstudyId = Number(sessionStorage.getItem(`${this.taskId}-basicstudyId`));
          this.$api.kjxm.project.basicstudyGet(basicstudyId).then(response => {
            this.formData4 = response.data;
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
          this.applyLoading = false;
        }
      } else if (Number(cur) === 4) {
        this.activeForm = cur;
        sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
        this.applyLoading = false;
      } else if (Number(cur) === 5) {
        this.activeForm = cur;
        sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
        this.applyLoading = false;
      } else if (Number(cur) === 6) {
        this.activeForm = cur;
        sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
        this.applyLoading = false;
      } else if (Number(cur) === 7) {
        getFiles(sessionStorage.getItem(`${this.taskId}-projectId`)).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          const fileLists = []
          this.projectFileData.forEach((val, index) => {
            if (this.formData.isOldProject === '1') {
              this.projectFileData[index].c2 = '否';
            }
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
            fileLists.push(...this.projectFileData[index].fileIds)
          })
          if (fileLists.length > 0) {
            sessionStorage.setItem(`${this.taskId}-fileId`, res.data.length)
          }
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
          this.applyLoading = false;
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      } else {
        this.activeForm = cur;
        sessionStorage.setItem(`${this.taskId}-activeForm`, cur);
        this.applyLoading = false;
      }
    },
    getProjectId () {
      return sessionStorage.getItem(`${this.taskId}-projectId`)
    },
    isSubmit (name) {
      return sessionStorage.getItem(`${this.taskId}-${name}`) ? '已提交' : '未提交';
    },
    getDeclareTree () {
      return this.$api.kjxm.project.planCategoryDeclareTree().then(response => {
        this.projectCategoryOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDataTypes () {
      return getDictList(["project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "education", "duty", "platform_type", "expect_result_type"]).then(response => {
        this.dictTypes = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    createProjectLeaderOptions (value) {
      this.projectLeaderOptions.push({
        label: `${value}`,
        value,
        name: value
      });
    },
    remoteProjectLeaderMethod (search) {
      this.leaderLoading = true;

      this.$api.system.member.searchList({ name: search }).then(response => {
        this.projectLeaderOptions = response.data.map(val => ({
          ...val,
          label: `${val.name}-${val.idCard}`,
          value: `${val.name}-${val.idCard}`,
        }));
        this.leaderLoading = false;
      }).catch((e) => {
        this.leaderLoading = false;
        this.$message.error(e.toString());
      });
    },
    createProjectLinkerOptions (value) {
      this.projectLinkerOptions.push({
        label: `${value}`,
        value,
        name: value
      });
    },
    remoteProjectLinkerMethod (search) {
      this.linkerLoading = true;
      this.$api.system.member.searchList({ name: search }).then(response => {
        this.projectLinkerOptions = response.data.map(val => ({
          ...val,
          label: `${val.name}-${val.idCard}`,
          value: `${val.name}-${val.idCard}`,
        }));
        this.linkerLoading = false;
      }).catch((e) => {
        this.linkerLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit2 ({ validateResult, firstError }) {
      if (validateResult === true) {
        //
        if (this.site_tag === 'jtt') {
          if (this.lengthLimitObj.background > this.maxlength) {
            this.$message.error(`（一）研究背景： 当前字数：${this.lengthLimitObj.background}，限制字数：${this.maxlength}`)
            return false;
          }
          if (this.lengthLimitObj.goal > this.maxlength) {
            this.$message.error(`（二）研究目的与意义： 当前字数：${this.lengthLimitObj.goal}，限制字数：${this.maxlength}`)
            return false;
          }
          if (this.lengthLimitObj.actuality > this.maxlength) {
            this.$message.error(`（三）国内外研究现状与评价： 当前字数：${this.lengthLimitObj.actuality}，限制字数：${this.maxlength}`)
            return false;
          }
        } else {
          if (this.lengthLimitObj.background > this.maxlength * 3) {
            this.$message.error(`（一）研究背景：1 当前字数：${this.lengthLimitObj.background}，限制字数：${this.maxlength * 3}`)
            return false;
          }
          if (this.lengthLimitObj.goal > this.maxlength * 3) {
            this.$message.error(`（二）研究目的与意义： 当前字数：${this.lengthLimitObj.goal}，限制字数：${this.maxlength * 3}`)
            return false;
          }
          if (this.lengthLimitObj.actuality > this.maxlength * 3) {
            this.$message.error(`（三）国内外研究现状与评价： 当前字数：${this.lengthLimitObj.actuality}，限制字数：${this.maxlength * 3}`)
            return false;
          }
        }
        this.formData2.projectId = Number(sessionStorage.getItem(`${this.taskId}-projectId`));
        // 校验论文内容
        const isValidate = this.$refs["project-background-literature"].checkData();
        if (!isValidate) {
          return false;
        }
        this.applyLoading = true;
        if (!sessionStorage.getItem(`${this.taskId}-backgroundId`)) {
          this.$api.kjxm.project.backgroundAdd(this.formData2).then(response => {
            // this.backgroundId = response.data.id;
            sessionStorage.setItem(`${this.taskId}-backgroundId`, response.data.id)
            this.$message.success('提交成功');
            this.onCurChanged(2);
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjxm.project.backgroundEdit({
            ...this.formData2,
            id: Number(sessionStorage.getItem(`${this.taskId}-backgroundId`))
          }).then(response => {
            this.onCurChanged(2);
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }

      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit ({ validateResult, firstError }) {
      if (validateResult === true) {
        if (Number(this.formData.adviceFunding) < Number(this.formData.subsidyFunding)) {
          const label = this.site_tag === 'jtt' ? '申请厅补助经费' : '申请集团补助经费';
          this.$message.error(`建议经费总概算:${this.formData.adviceFunding}不能小于${label}:${this.formData.subsidyFunding}`);
          return false
        }
        const age = getIdCardAge(this.formData.projectLeader.idCard)
        if (age < 18) {
          this.$message.error(`项目主要负责人 身份证号 需满18岁`);
          return false
        }
        const birthday = getIdCardBirthday(this.formData.projectLeader.idCard)
        if (birthday.slice(0, 7) !== this.formData.projectLeader.birthDate) {
          this.$message.error(`项目主要负责人身份证号与出生年月 不一致`);
          return false
        }
        // [this.formData.startDate, this.formData.endDate] = this.formData.dateRange;
        this.applyLoading = true;
        this.formData.keyWord = this.formData.keyWordList.join(",")
        if (!sessionStorage.getItem(`${this.taskId}-projectId`)) {
          this.$api.kjxm.project.add({
            ...this.formData,
            // projectStatus: this.formData.isOldProject === '1' ? null : '1',
            // keyWord: this.formData.keyWord.join(",")
          }).then(response => {
            // this.projectId = response.data.id;
            sessionStorage.setItem(`${this.taskId}-projectId`, response.data.id)
            this.$message.success('提交成功');
            // this.activeForm = 1;
            this.disableDate = {
              before: dayjs(this.formData.startDate, "YYYY-MM-DD").endOf('month').subtract(1, 'month').format(),
              after: dayjs(this.formData.endDate, "YYYY-MM-DD").endOf('month').subtract(0, 'month').format(),
            }
            this.adviceFunding = this.formData.adviceFunding;
            this.subsidyFunding = this.formData.subsidyFunding;
            this.fundingObj = {
              adviceFunding: this.formData.adviceFunding,
              subsidyFunding: this.formData.subsidyFunding
            }
            this.onCurChanged(1);
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjxm.project.edit({
            ...this.formData,
            // keyWord: this.formData.keyWord.join(","),
            id: Number(sessionStorage.getItem(`${this.taskId}-projectId`)),
            // projectStatus: this.formData.isOldProject === '1' ? null : '1',
          }).then(response => {
            // this.activeForm = 1;
            // 根据当前项目限定时间
            this.disableDate = {
              before: dayjs(this.formData.startDate, "YYYY-MM-DD").endOf('month').subtract(1, 'month').format(),
              after: dayjs(this.formData.endDate, "YYYY-MM-DD").endOf('month').subtract(0, 'month').format(),
            }
            this.adviceFunding = this.formData.adviceFunding;
            this.subsidyFunding = this.formData.subsidyFunding;
            this.fundingObj = {
              adviceFunding: this.formData.adviceFunding,
              subsidyFunding: this.formData.subsidyFunding
            }
            this.onCurChanged(1);
            // this.projectId = response.data.projectId;
            // this.$message.success('提交成功');
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }


      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit3 ({ validateResult, firstError }) {
      if (validateResult === true) {
        if (this.site_tag === 'jtt') {
          if (this.lengthLimitObj.researchContent > this.maxlength) {
            this.$message.error(`（一）研究内容、拟解决的关键问题、研究方法、技术路线及创新点： 当前字数：${this.lengthLimitObj.researchContent}，限制字数：${this.maxlength}`)
            return false;
          }
          if (this.lengthLimitObj.expectedGoal > this.maxlength) {
            this.$message.error(`（四）项目预期目标及经济、社会效益： 当前字数：${this.lengthLimitObj.expectedGoal}，限制字数：${this.maxlength}`)
            return false;
          }
        } else {
          if (this.lengthLimitObj.researchContent > this.maxlength * 3) {
            this.$message.error(`（一）研究内容、拟解决的关键问题、研究方法、技术路线及创新点： 当前字数：${this.lengthLimitObj.researchContent}，限制字数：${this.maxlength * 3}`)
            return false;
          }
          if (this.lengthLimitObj.expectedGoal > this.maxlength * 3) {
            this.$message.error(`（四）项目预期目标及经济、社会效益： 当前字数：${this.lengthLimitObj.expectedGoal}，限制字数：${this.maxlength * 3}`)
            return false;
          }
        }
        // 年度研究计划 非空判断
        const isValidate = this.$refs["project-research-plan"].checkData()
        if (!isValidate) {
          return false;
        }
        const isValidate2 = this.$refs["project-approach-expect-results"].checkData()
        if (!isValidate2) {
          return false;
        }
        const projectResearchPlan = this.formData3.projectResearchPlan.map((row, index) => ({
          // ...row,
          startDate: row.startDate,
          endDate: row.endDate,
          content: row.content,
          sort: index + 1
        }))
        this.formData3.projectId = Number(sessionStorage.getItem(`${this.taskId}-projectId`));
        this.applyLoading = true;
        if (!sessionStorage.getItem(`${this.taskId}-approachId`)) {
          this.$api.kjxm.project.approachAdd({
            ...this.formData3,
            projectResearchPlan
          }).then(response => {
            // this.approachId = response.data.id;
            sessionStorage.setItem(`${this.taskId}-approachId`, response.data.id);
            this.$message.success('提交成功');
            this.onCurChanged(3)
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjxm.project.approachEdit({
            ...this.formData3,
            projectResearchPlan,
            id: Number(sessionStorage.getItem(`${this.taskId}-approachId`))
          }).then(response => {
            this.onCurChanged(3)
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }
      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit4 ({ validateResult, firstError }) {
      if (validateResult === true) {
        if (this.site_tag === 'jtt') {
          if (this.lengthLimitObj.achievement > this.maxlength) {
            this.$message.error(`（一）与本项目有关的研究工作积累和已取得的研究工作成就： 当前字数：${this.lengthLimitObj.achievement}，限制字数：${this.maxlength}`)
            return false;
          }
          if (this.lengthLimitObj.conditions > this.maxlength) {
            this.$message.error(`（二）项目依托工程情况及其它必要支撑条件： 当前字数：${this.lengthLimitObj.conditions}，限制字数：${this.maxlength}`)
            return false;
          }
        } else {
          if (this.lengthLimitObj.achievement > this.maxlength * 3) {
            this.$message.error(`（一）与本项目有关的研究工作积累和已取得的研究工作成就： 当前字数：${this.lengthLimitObj.achievement}，限制字数：${this.maxlength * 3}`)
            return false;
          }
          if (this.lengthLimitObj.conditions > this.maxlength * 3) {
            this.$message.error(`（二）项目依托工程情况及其它必要支撑条件： 当前字数：${this.lengthLimitObj.conditions}，限制字数：${this.maxlength * 3}`)
            return false;
          }
        }

        this.formData4.projectId = Number(sessionStorage.getItem(`${this.taskId}-projectId`));
        this.applyLoading = true;
        if (!sessionStorage.getItem(`${this.taskId}-basicstudyId`)) {
          this.$api.kjxm.project.basicstudyAdd(this.formData4).then(response => {
            // this.basicstudyId = response.data.id;
            sessionStorage.setItem(`${this.taskId}-basicstudyId`, response.data.id)
            this.$message.success('提交成功');
            this.onCurChanged(4)
            // this.activeForm = 4;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjxm.project.basicstudyEdit({
            ...this.formData4,
            id: Number(sessionStorage.getItem(`${this.taskId}-basicstudyId`))
          }).then(response => {
            // this.activeForm = 4;
            this.onCurChanged(4)
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }
      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit5 () {
      const isValidate = this.$refs["project-unit"].checkData()
      if (!isValidate) {
        return false;
      }
      this.applyLoading = true;
      this.$api.kjxm.project.companyAdd(this.formData5.unitList).then(response => {
        if (!sessionStorage.getItem(`${this.taskId}-companyId`)) {
          this.$message.success('提交成功');
        }
        sessionStorage.setItem(`${this.taskId}-companyId`, this.formData5.unitList.length)
        this.onCurChanged(5)
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit6 () {
      // 需要判断必填
      const data1 = this.formData6.memberList.filter((val) => ['1', '2'].includes(val.type));
      const data2 = this.formData6.memberList.filter((val) => val.type === '3');
      if (data1.length <= 0) {
        this.$message.error('项目负责人不能为空');
        return
      }
      // if (data2.length <= 0) {
      //   this.$message.error('主要研究人员不能为空');
      //   return
      // }
      this.applyLoading = true;
      this.$api.kjxm.project.memberAdd(this.formData6.memberList).then(response => {
        if (!sessionStorage.getItem(`${this.taskId}-memberId`)) {
          this.$message.success('提交成功');
        }
        sessionStorage.setItem(`${this.taskId}-memberId`, this.formData6.memberList.length)
        this.onCurChanged(6)
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    onSubmit7 () {
      // 判断经费来源 经费支出 是否一致
      const sum1 = (Number(((this.formData7.inTbBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.inZcBudget || 0) * 100).toFixed(2))) / 100;
      const sum2 = (Number(((this.formData7.outTbSbBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbSzsbBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbSbzzBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbClBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbSyjgBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbRldlBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbClvBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbHyBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbGjhzBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbCbBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbLwBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbZjzxBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbQtBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbGlBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outTbJxzcBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcSbBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcSzsbBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcSbzzBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcClBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcSyjgBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcRldlBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcClvBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcHyBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcGjhzBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcCbBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcLwBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcZjzxBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcQtBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcGlBudget || 0) * 100).toFixed(2)) + Number(((this.formData7.outZcJxzcBudget || 0) * 100).toFixed(2))) / 100;
      if (sum1 !== sum2) {
        this.$message.error('经费来源与经费支出金额不一致');
        return false;
      }
      this.applyLoading = true;
      if (!sessionStorage.getItem(`${this.taskId}-budgetId`)) {
        this.$api.kjxm.project.budgetAdd({
          ...this.formData7,
          projectId: Number(sessionStorage.getItem(`${this.taskId}-projectId`))
        }).then(response => {
          sessionStorage.setItem(`${this.taskId}-budgetId`, response.data.id);
          if (!sessionStorage.getItem(`${this.taskId}-budgetId`)) {
            this.$message.success('提交成功');
          }
          this.onCurChanged(7)
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      } else {
        this.$api.kjxm.project.budgetEdit({
          ...this.formData7,
          projectId: Number(sessionStorage.getItem(`${this.taskId}-projectId`)),
          id: Number(sessionStorage.getItem(`${this.taskId}-budgetId`)),
        }).then(response => {
          if (!sessionStorage.getItem(`${this.taskId}-budgetId`)) {
            this.$message.success('提交成功');
          }
          this.onCurChanged(7)
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      }
    },
    onSubmit8 (type) {
      if (type === 1) {
        this.applyLoading = true;
        const sysAttMainIds = []
        this.projectFileData.forEach(val => {
          sysAttMainIds.push(...val.fileIds)
        })
        this.$api.kjxm.project.edit({
          // projectStatus: this.formData.isOldProject === '1' ? null : '1',
          id: Number(sessionStorage.getItem(`${this.taskId}-projectId`)),
          sysAttMainVo: {
            sysAttMainIds,
          }
        }).then(val => {
          sessionStorage.setItem(`${this.taskId}-fileId`, this.projectFileData.length);
          this.$message.success('暂存成功');
          this.applyLoading = false;
          // this.close();
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      } else {

        if (this.formData.isOldProject === '1') {
          // if (this.projectFileData[3].fileIds.length <= 0) {
          //   this.$message.error("需要上传已盖章申报书");
          //   return false;
          // }
        } else {
          const isValidate = this.projectFileData.every(val => {
            if (val.require && val.fileIds.length <= 0) {
              this.$message.error(`需要上传${val.c1}`);
              return false;
            }
            return true
          })
          if (!isValidate) {
            return false
          }

          // if (this.projectFileData[0].fileIds.length <= 0 && this.site_tag === 'jtt') {
          //   this.$message.error("需要上传查新报告");
          //   return false;
          // }
          // if (this.projectFileData[1].fileIds.length <= 0) {
          //   this.$message.error("需要上传归口管理单位科研诚信承诺书");
          //   return false;
          // }
          // if (this.projectFileData[2].fileIds.length <= 0) {
          //   this.$message.error("需要上传项目组科研诚信承诺书");
          //   return false;
          // }
        }
        if (!sessionStorage.getItem(`${this.taskId}-projectId`)) {
          this.$message.error("基本信息还未提交")
          this.applyLoading = false;
          return false;
        }
        if (!sessionStorage.getItem(`${this.taskId}-backgroundId`)) {
          this.$message.error("立项背景和依据还未提交")
          this.applyLoading = false;
          return false;
        }
        if (!sessionStorage.getItem(`${this.taskId}-approachId`)) {
          this.$message.error("研究方案还未提交");
          this.applyLoading = false;
          return false;
        }
        if (!sessionStorage.getItem(`${this.taskId}-basicstudyId`)) {
          this.$message.error("研究基础还未提交");
          this.applyLoading = false;
          return false;
        }
        if (!sessionStorage.getItem(`${this.taskId}-companyId`)) {
          this.$message.error("单位信息还未提交");
          this.applyLoading = false;
          return false;
        }
        if (!sessionStorage.getItem(`${this.taskId}-memberId`)) {
          this.$message.error("研究人员还未提交");
          this.applyLoading = false;
          return false;
        }
        if (!sessionStorage.getItem(`${this.taskId}-budgetId`)) {
          this.$message.error("经费预算还未提交");
          this.applyLoading = false;
          return false;
        }
        this.applyLoading = true;
        this.isCommit = true;
        const sysAttMainIds = []
        this.projectFileData.forEach(val => {
          sysAttMainIds.push(...val.fileIds)
        })
        if (this.formData.isOldProject === '1') {
          this.$api.kjxm.project.projectOldSubmit({
            id: Number(sessionStorage.getItem(`${this.taskId}-projectId`)),
            sysAttMainVo: {
              sysAttMainIds
            }
          }).then(val => {
            sessionStorage.setItem(`${this.taskId}-fileId`, this.projectFileData.length);
            this.$message.success('提交成功');
            this.applyLoading = false;
            this.isCommit = false;
            this.close();
          }).catch((e) => {
            this.applyLoading = false;
            this.isCommit = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjxm.project.projectSubmit({
            // projectStatus: this.formData.isOldProject === '1' ? null : '2',
            id: Number(sessionStorage.getItem(`${this.taskId}-projectId`)),
            sysAttMainVo: {
              sysAttMainIds
            }
          }).then(val => {
            sessionStorage.setItem(`${this.taskId}-fileId`, this.projectFileData.length);
            this.$message.success('提交成功');
            this.applyLoading = false;
            this.isCommit = false;
            this.close();
          }).catch((e) => {
            this.applyLoading = false;
            this.isCommit = false;
            this.$message.error(e.toString());
          });
        }
      }
    },
    activated () {
      // const newid = Number(new Date().getTime()) + Number(Math.random() * 10)
      this.tinymceFlag += 1
    },


  }
}
</script>

<style lang="less" scoped>
.step-form {
  padding: 0 24px;
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}

/* popup的样式 */
.ol-popup {
  position: absolute;
  -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  padding: 15px;
  border-radius: 4px;
  transform: translate(10px, 25px);
  min-width: 200px;
  text-align: left;
  background-color: rgba(255, 255, 255, 0.8);
}

.ol-popup:after,
.ol-popup:before {
  top: 100%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}

.ol-popup:after {
  border-width: 10px;
  left: 50%;
  margin-left: -10px;
}

.ol-popup:before {
  border-width: 11px;
  left: 50%;
  margin-left: -11px;
}

.ol-popup-closer {
  text-decoration: none;
  position: absolute;
  top: 2px;
  right: 8px;
}

.ol-popup-closer:after {
  content: "x";
}

.ol-popup-content {
  font-size: 14px;
}

.ol-popup-content-tab td:nth-child(2n+1) {
  font-weight: bold;
}

.ol-popup-content-tab td:nth-child(2n) {}
</style>
